package com.zlt.bkparking.controller.parking;


import com.github.pagehelper.PageInfo;
import com.zlt.bkparking.dto.CarAddressDTO;
import com.zlt.bkparking.dto.ParkingOrderDTO;
import com.zlt.bkparking.service.PlOrderService;
import com.zlt.bkparking.vo.CarAddressVO;
import com.zlt.bkparking.vo.ParkingOrderVO;
import com.zlt.bkparking.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


@Slf4j
@RestController
@RequestMapping("order")
@Api(value = "PlOrderController-Swagger调试",tags = "Swagger 调试")
public class PlOrderController {

    @Autowired
    private PlOrderService plOrderService;

    /**
     * 根据订单条件，查询订单信息
     * @param parkingOrderDTO
     * @return
     */
    @ApiOperation("停车场管理员订单的接口")
    @PostMapping("selectPlOrder")
    public Result selectPlOrder( @ApiParam   ParkingOrderDTO parkingOrderDTO){
        System.out.println("获取所有停车场订单的数据{}"+parkingOrderDTO.toString());
        try {
            PageInfo<ParkingOrderVO> pageInfo=plOrderService.selectPlOrder(parkingOrderDTO);
            System.out.println("管理员订单{}"+pageInfo);
            log.debug("管理员订单{}"+pageInfo);
            return Result.ok("查询成功",pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("查询失败"+e.getMessage());
        }
    }

    /**
     * 停车场管理员对订单进行退款
     * @param poNo
     * @return
     */
    @ApiOperation("停车场管理员订单退款的接口")
    @PostMapping("orderRefund")
    public Result orderRefund( @ApiParam   String poNo){
        System.out.println("申请退款订单的数据{}"+poNo);
        try {
//            Boolean isSuccess=plOrderService.orderRefund(poNo);
//            return isSuccess ? Result.ok("退款成功"):Result.error("退款失败");
              return Result.ok("服务开发中，尽请期待");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("退款失败");
        }
    }

    /**
     * 根据对应停车场统计对应的订单，按照订单状态进行统计
     * @return
     */
    @ApiOperation("停车场管理员订单统计的接口1")
    @GetMapping("statistic1")
    public Result statisticOrder1(){
        try {
            List<Map<String,Object>> list=plOrderService.statisticOrder1();
            System.out.println("查询的数据："+list);
            return (list!=null && !list.isEmpty()) ? Result.ok("查询成功",list) : Result.error("查询失败");
        } catch (Exception e) {
            e.printStackTrace();
            return  Result.error("查询失败");
        }
    }

    /**
     * 根据对应停车场统计对应的订单，按照订单状态进行统计
     * @return
     */
    @ApiOperation("停车场管理员订单统计的接口2")
    @PostMapping("statistic2")
    public Result statisticOrder2(ParkingOrderDTO parkingOrderDTO){
        System.out.println(parkingOrderDTO);
        try {
            List<List<Object>> list=plOrderService.statisticOrder2(parkingOrderDTO);
            System.out.println("查询的数据："+list);
            return (list!=null && !list.isEmpty()) ? Result.ok("查询成功",list) : Result.error("查询失败");
        } catch (Exception e) {
            e.printStackTrace();
            return  Result.error("查询失败");
        }
    }


    /**
     * 根据对应停车场统计对应的订单，按照订单状态进行统计
     * @return
     */
    @ApiOperation("停车场管理员订单统计的接口3")
    @PostMapping("statistic3")
    public Result statisticCarAddress(ParkingOrderDTO parkingOrderDTO){

        System.out.println(parkingOrderDTO);
        try {
            List<List<Map<String, Object>>> list=plOrderService.statisticCarAddress(parkingOrderDTO);
            System.out.println("查询的数据："+list);
            return (list!=null && !list.isEmpty()) ? Result.ok("查询成功",list) : Result.error("查询失败");
        } catch (Exception e) {
            e.printStackTrace();
            return  Result.error("查询失败");
        }
    }

    /**
     * 根据对应停车场统计对应的订单，按照订单状态进行统计
     * @return
     */
    @ApiOperation("停车场车位统计的接口4")
    @PostMapping("selectCarAddress")
    public Result selectCarAddress(){

        try {
            List<CarAddressVO> list=plOrderService.selectCarAddress();
            System.out.println("查询的数据："+list.size()+" "+list);
            return (list!=null && !list.isEmpty()) ? Result.ok("查询成功",list) : Result.error("查询失败");
        } catch (Exception e) {
            e.printStackTrace();
            return  Result.error("查询失败");
        }
    }



    /**
     * 根据对应停车场统计对应的订单，按照订单状态进行统计
     * @return
     */
    @ApiOperation("停车场车位统计的接口4")
    @PostMapping("updateCarAddress")
    public Result updateCarAddress(CarAddressDTO carAddressDTO){
        System.out.println("carAddressDTO=="+carAddressDTO);
        try {
            Boolean success=plOrderService.updateCarAddress(carAddressDTO);
            return (success) ? Result.ok("修改成功") : Result.error("修改失败");
        } catch (Exception e) {
            e.printStackTrace();
            return  Result.error("查询失败");
        }
    }




}
